package com.example.archermind.myapplication;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

public class NotificationForegroundService extends Service {
    private  final String TAG = getClass().toString();

    public NotificationForegroundService() {
        Log.d(TAG,"NotificationForegroundService init");
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        useForeground("前台服务","童年");
        Log.d(TAG,"onCreate");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG,"onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    public void useForeground(CharSequence tickerText, String currSong) {
        Log.d(TAG,"tickerText:"+tickerText+" currSong:"+currSong);
        String CHANNEL_ID = "com.jpcc.vw.music.ui.other.play.service";
        String CHANNEL_NAME = "MusicPlayService";
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID,CHANNEL_NAME,NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        manager.createNotificationChannel(channel);
        startForeground(1000,new Notification.Builder(getApplicationContext(),CHANNEL_ID).build());

    }
}
